<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/

/**
 * 博客后台分类控制器，负责，业务流程判断
 * 后台所有操作都需要权限，必需继承 CommonAction 控制器
 */
Class GetlistAction extends CommonAction{

	/**
	 * 博客分类列表
	 * @return [type] [description]
	 */
	Public function index(){
		$this->assign('bloglist', M('getlist')->blogAllList());
		$this->display();
	}

	/**
	 * 更新博客分类排序与删除
	 * @return [type] [description]
	 */
	Public function update(){
		if (ISPOST) {
			$postupdate = trim(G('post.update'));
			$postdel = trim(G('post.del'));
			if (!empty($postupdate)) {
				$postord = G('post.ord');
				if (empty($postord)) {
					$this->error('Shit,排序失败？');
				}
				$data = (!empty($postord)) ? G('post.ord') : array();
				foreach ($data as $k => $v) {
					if (!is_numeric($v)) {
						$this->error('排序只能使用数字！');
					}
				}
				if (M('getlist')->upDateList($data)) {
					$this->success('更新排序成功～！', U('index'));
				}
			} else if (!empty($postdel)) {
				$postid = G('post.id');
				if (!empty($postid)) {
					$data = G('post.id');
					$check = M('getlist')->blogAllList();
					foreach ($data as $v) {
						if (!empty($check[$v]['countpost'])) {
							if ($check[$v]['countpost']) {
								$this->error('分类中存在日志，不能批量删除～！');
							}
						}
					}
					if (M('getlist')->delList($data)) {
						$this->success('批量删除成功～！', U('index'));
					}
				} else {
					$this->error('Shit, 我没有选择？');
				}
			}
		}
	}

	/**
	 * 单一删除分类
	 * @return [type] [description]
	 */
	Public function del(){
		$check = M('getlist')->blogAllList();
		if ($check[G('get.lid')]['countpost']) {
			$this->error('分类中存在日志，不能删除～！');
		}
		if (M('getlist')->delList(G('get.lid'))) {
			$this->success('删除成功～！', U('index'));
		}
	}

	/**
	 * 添加分类页面
	 */
	Public function add(){
		$check = false;
		$geteid = trim(G('get.eid'));
		if (!empty($geteid)) {
			$M = M('getlist')->getList(G('get.eid'));
			$this->assign('title', $M['title']);
			$this->assign('path', $M['path']);
			$this->assign('des', $M['des']);
			$this->assign('keyword', $M['keyword']);
			$this->assign('ord', $M['ord']);
			$this->assign('date', $M['date']);
			$this->assign('time', $M['time']);
			$check = true;
		} else {
			$this->assign('ord', '100');
		}
		$this->assign('check', $check);
		$this->display();
	}

	/**
	 * 添加与修改以的分类
	 * @return [type] [description]
	 */
	Public function checkdata(){
		if (ISPOST) {
			$posttitle = trim(G('post.title'));
			if (empty($posttitle)) {
				$this->error('标题不能不空～！');
			}
			if (M('getlist')->writeData(G('post.'))){
				$this->success('添加成功～！', U('index'));
			} else {
				$this->error('添加失败～！');
			}
		}
	}
}